package com.hliushi.hotel.mq;

import com.hliushi.hotel.constants.MqConstants;
import com.hliushi.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author llhuang10
 * @date 2021/9/9 21:29
 */
@Slf4j
@Component
public class HotelListener {


    @Resource
    private IHotelService hotelService;

    /**
     * 监听酒店新增或修改的业务
     *
     * @param id 接收的消息内容是id
     */
    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void listenHotelInsertOrUpdate(Long id) {
        hotelService.insertById(id);
    }

    /**
     * 监听酒店删除的业务
     *
     * @param id 接收的消息内容是id
     */
    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void listenHotelDelete(Long id) {
        hotelService.deleteById(id);
    }
}
